﻿using System;
using Core.Library;
using DataObject.Article;
using DataObject.Category;
using DataObject;
using System.Web.UI.WebControls;

public partial class Controls_Article_Box_NewsFeed : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            ListTopHighlight();
    }

    private void ListTopHighlight()
    {
        var lstArticle = ArticleController.Article_GetTopHighlight(SettingValues.PageSize_5);
        if (lstArticle.Count > 0)
        {
            var categoryName = CategoryController.GetCategoryName(lstArticle[0].CategoryId);
            var articleHref = UrlHelpers.ArticleDetail(categoryName, ConvertUtility.ToInt32(lstArticle[0].ArticleId), lstArticle[0].Title);

            var imgHref = string.Format("{0}/Thumb.ashx?Id={1}&tId={2}&Size=200", Constants.ThumbImage, lstArticle[0].ArticleId, (int)CategoryType.Article);

            rptHighlight.DataSource = lstArticle;
            rptHighlight.DataBind();
        }
    }

    protected void rptHighlight_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            var ArticleId = ConvertUtility.ToInt32(((HiddenField)e.Item.FindControl("hfArticleId")).Value);
            var ltrImage = ((Literal)e.Item.FindControl("ltrImage"));

            var imgHref = string.Format("{0}/Thumb.ashx?Id={1}&tId={2}&Size=70&Fix=highlight", Constants.ThumbImage, ArticleId, (int)CategoryType.Article);
            ltrImage.Text = string.Format("<img src=\"{0}\" alt=\"\" />", imgHref); 
        }
    }
}